<?php
require_once('../../core.php');

	//Get the selected allys
	$selected = array();
	if (isset($_SESSION['selected'])) {
		$selected = $_SESSION['selected'];
    }

    
	//Remove
	if (isset($_GET['remove'])) {
		$remove = $_GET['remove'];
		
		for($i = 0; $i < count($selected); $i++) {
			if ($selected[$i]->id == $remove) {
				array_splice($selected, $i, 1);
				break;
			}
		}
	}

	if (isset($_POST['submit']) && $_POST['submit'] == 10228)  { /*Lost*/
		//Our ally
		$ally                       = get_ally(10228);
		$ally->color                = get_color(count($selected));
		$selected[count($selected)] = $ally;
	} else if (isset($_GET['submit'])) { /*Any other*/
		if (isset($_GET['ally'])) {
			$ally = get_ally($_GET['ally']);
			$ally->id    = $_GET['ally'];
			$ally->name  = $ally->name;
			$ally->color = get_color(count($selected));
			$selected[count($selected)] = $ally;
		}
	} else if(isset($_POST['reset'])) {
		$selected = array();
	}
	
	$_SESSION['selected'] = $selected;
    
    
    put_map(600);

?>
